package com.edu.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.Scar;
import com.edu.entity.Shopping;
import com.edu.service.UserService;
import com.edu.service.impl.UserServiceImpl;

/**
 * Servlet implementation class scarServlet
 */
@WebServlet("/scarServlet")
public class scarServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		UserService shopService=new UserServiceImpl();
		String cName=request.getParameter("cName");
		System.out.println(cName);
		String cPrice=request.getParameter("cPrice");
		System.out.println(cPrice);
		String cUrl=request.getParameter("cUrl");
		System.out.println(cUrl);
		Scar shop=new Scar(cUrl,cName,cPrice);
		System.out.println(shop);
		 
        boolean result = shopService.added(shop);
        List<Scar> scar=shopService.selectd(cName);
        request.setAttribute("scar", scar);
        //如果添加成功 转到商品购物
        if(result) {
        	request.getRequestDispatcher("shop.jsp").forward(request, response);
           
        }else {
            //失败的话 转到商品浏览页
            request.getRequestDispatcher("index.jsp").forward(request, response);

        }            
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
